package spring.test1;

import org.junit.After;
import org.junit.Before;
import org.junit.Test;
import org.springframework.context.support.ClassPathXmlApplicationContext;

public class Demo3_BeanLifeCycle {
    ClassPathXmlApplicationContext applicationContext;

    @Before
    public void setUp() {
        //创建容器时单例bean被创建
        applicationContext = new ClassPathXmlApplicationContext("ioc/applicationContext.xml");
    }

    @Test
    public void testLifeCycle() {
        //多例对象不使用就不会被创建
        Object beanLifeCycle = applicationContext.getBean("beanLifeCycle");
        System.out.println(beanLifeCycle.getClass().getName() + "存活...");
    }

    @After
    public void finish() {
        //关闭容器时单例Bean被销毁，close方法是ClassPathXmlApplicationContext独有方法，不要使用转型
        applicationContext.close();
    }
}
